import Vue from 'vue';
import i18n from '@/assets/language/index.js'
import confirm from './confirm.vue';

const confirmConstructor = Vue.extend(confirm);
const confirmDom = new confirmConstructor({
  el: document.createElement('div'),
});
document.body.appendChild(confirmDom.$el);
confirm.install = (vm) => {
  vm.prototype.$customConfirm = (obj) => {
    confirmDom.$props.content = obj.content || "删除会清空数据且不可撤销 确认删除？";
    confirmDom.$props.icon = obj.icon || "el-icon-warning"
    confirmDom.$props.title = obj.title || i18n.t('recipe.information_prompt');
    confirmDom.$props.cancelTxt = obj.cancelTxt || i18n.t('common.cancel');
    confirmDom.$props.confirm = obj.confirm || i18n.t('common.determine');
    confirmDom.$props.coverTxt = obj.coverTxt || '覆 盖';
    confirmDom.$props.isShowCover = obj.isShowCover || false;
    confirmDom.open();
    confirmDom.$on('confirm', () => {
      if (obj.onok && typeof obj.onok == "function") {
        obj.onok();
      }
      confirmDom.$off('confirm');
      confirmDom.$off('cancel');
      confirmDom.$off('cover');
    });

    confirmDom.$on('cancel', () => {
      if (obj.oncancel && typeof obj.oncancel == "function") {
        obj.oncancel();
      }
      confirmDom.$off('cancel');
      confirmDom.$off('confirm');
      confirmDom.$off('cover');
    });
    confirmDom.$on('cover', () => {
      if (obj.cover && typeof obj.cover == "function") {
        obj.cover();
      }
      confirmDom.$off('cancel');
      confirmDom.$off('confirm');
      confirmDom.$off('cover');
    });



  };
};

export default confirm;